/*
 Simple Installer - Install your own Custom Modules or Plugins.
 Copyright (C) 2011	Cha0z
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 */

#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <stdio.h>
#include <string.h>

// Your Header Files which you have created with bin2c.

PSP_MODULE_INFO("SimpleInstaller", 0, 1, 0);

#define printf pspDebugScreenPrintf

void WriteFile(char *file, void *buf, int size)
{
    SceUID fd = sceIoOpen(file, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
    if(fd >= 0)
    {
        sceIoWrite(fd, buf, size);
        sceIoClose(fd);
    }
}

int main(void)
{
    SceCtrlData pad;

    pspDebugScreenInit();

    printf("Simple Installer\n");
    printf("by Cha0z\n\n");

    sceKernelDelayThread(1 * 1000 * 1000);

    printf("Press X to install .\n");
    printf("Press O to uninstall .\n");
    printf("Press R to exit.\n\n");

    while(1)
    {
        sceCtrlReadBufferPositive(&pad, 1);

        if(pad.Buttons & PSP_CTRL_CROSS)
        {
			WriteFile("ms0:/data.dat", (void*)data, size_data);

			printf("Done\n\n");
			sceKernelDelayThread(1 * 1000 * 1000)
			break;
        }
        else if(pad.Buttons & PSP_CTRL_CIRCLE)
        {
            sceIoRemove("ms0:/data.dat");

            printf("Done\n\n");
            sceKernelDelayThread(1 * 1000 * 1000);
            break;
        }
        else if(pad.Buttons & PSP_CTRL_RTRIGGER) break;
    }

    printf("Auto exiting in 3 seconds...");
    sceKernelDelayThread(3 * 1000 * 1000);
    sceKernelExitGame();

    return 0;
}
